package com.dream.entity;

import lombok.Data;

@Data
public class ResponseResult<T> {

    /**
     * 响应状态码
     */
    private int code;
    /**
     * 异常信息
     */
    private String message;
    /**
     * 响应数据
     */
    private T data;

    public static <T> ResponseResult<T> success(String message) {
        return success(0, message, null);
    }

    public static <T> ResponseResult<T> success(String message, T data) {
        return success(0, message, data);
    }

    public static <T> ResponseResult<T> success(T data) {
        return success(0, null, data);
    }

    public static <T> ResponseResult<T> success(int code, String message, T data) {
        ResponseResult<T> r = new ResponseResult<>();
        r.setCode(code);
        r.setMessage(message);
        r.setData(data);
        return r;
    }

    public static <T> ResponseResult<T> fail(String message) {
        return fail(-1, message, null);
    }

    public static <T> ResponseResult<T> fail(int code, String message) {
        return fail(code, message, null);
    }

    public static <T> ResponseResult<T> fail(int code, String message, T data) {
        ResponseResult<T> r = new ResponseResult<>();
        r.setCode(code);
        r.setMessage(message);
        r.setData(data);
        return r;
    }
}
